home *** CD-ROM | disk | FTP | other *** search
/ Chip 2011 November / CHIP_2011_11.iso / Programy / Inne / Gry / Carnage_Contest / scripts / CC Original / weapons / Arrow Rain.lua < prev    next >
Text File  |  2010-08-31  |  5KB  |  138 lines

  1. --------------------------------------------------------------------------------
  2. -- Weapon Arrow Rain + Projectile Arrow
  3. -- Original Carnage Contest Weapon
  4. -- Script by DC, August 2009, www.UnrealSoftware.de
  5. --------------------------------------------------------------------------------
  6.  
  7. -- Setup Tables
  8. if cc==nil then cc={} end
  9. cc.arrowrain={}
  10. cc.arrowrain.arrow={}
  11.  
  12. -- Load & Prepare Ressources
  13. cc.arrowrain.gfx_wpn=loadgfx("weapons/arrowrain.png")                    -- Weapon Image
  14. setmidhandle(cc.arrowrain.gfx_wpn)
  15. cc.arrowrain.gfx_pro=loadgfx("weapons/arrow.bmp")                        -- Projectile Image
  16. setmidhandle(cc.arrowrain.gfx_pro)
  17. cc.arrowrain.sfx_attack=loadsfx("arrow_shoot.ogg")                        -- Attack Sound
  18. cc.arrowrain.sfx_impact=loadsfx("arrow_impact.ogg")                        -- Impact Sound
  19.  
  20. --------------------------------------------------------------------------------
  21. -- Weapon: Arrow Rain
  22. --------------------------------------------------------------------------------
  23.  
  24. cc.arrowrain.id=addweapon("cc.arrowrain","Arrow Rain",cc.arrowrain.gfx_wpn,0,3)    -- Add Weapon (0 uses, first in round 3)
  25.  
  26. function cc.arrowrain.draw()                                            -- Draw
  27.     -- Fade Dark
  28.     if weapon_shots>0 and weapon_timer<0.4 then
  29.         weapon_timer=weapon_timer+0.01
  30.     end
  31. end
  32.  
  33. function cc.arrowrain.attack(attack)                                    -- Attack
  34.     if (weapon_shots<=0) and (attack==1) then
  35.         -- No more weapon switching!
  36.         useweapon(0)
  37.         weapon_shots=weapon_shots+1
  38.         -- Random Seed
  39.         math.randomseed(getplayerx(0)*374+getplayery(0)*56+getframe()*123+getround()*98)
  40.         -- Spawn Arrows (amount depending on map size)
  41.         limit=math.ceil(getmapwidth()/4)
  42.         if limit>500 then
  43.             limit=500
  44.         end
  45.         for i=1,limit,1 do
  46.             pid=createprojectile(cc.arrowrain.arrow.id)
  47.             projectiles[pid]={}
  48.             projectiles[pid].x=math.random(0,getmapwidth())
  49.             projectiles[pid].y=-math.random(500,650)
  50.             projectiles[pid].sx=math.random(-40,40)*0.1
  51.             projectiles[pid].sy=math.random(150,200)*0.1
  52.             projectiles[pid].timer=i*math.random(2,3)
  53.         end
  54.         -- End Turn
  55.         endturn()
  56.     end
  57. end
  58.  
  59. --------------------------------------------------------------------------------
  60. -- Projectile: Arrow
  61. --------------------------------------------------------------------------------
  62.  
  63. cc.arrowrain.arrow.id=addprojectile("cc.arrowrain.arrow")        -- Add Projectile
  64.  
  65. function cc.arrowrain.arrow.draw(id)                            -- Draw
  66.     setbgcolor(0,0,0,weapon_timer,0.01)
  67.     if projectiles[id].timer<=0 then
  68.         -- Setup draw mode
  69.         setblend(blend_alpha)
  70.         setalpha(1)
  71.         setcolor(255,255,255)
  72.         setscale(1,1)
  73.         -- Calculate projectile rotation
  74.         setrotation(math.deg(math.atan2(projectiles[id].sx,-projectiles[id].sy)))
  75.         -- Draw projectile
  76.         drawimage(cc.arrowrain.gfx_pro,projectiles[id].x,projectiles[id].y)
  77.     end
  78. end
  79.  
  80. function cc.arrowrain.arrow.update(id)                            -- Update
  81.     -- Timer
  82.     if projectiles[id].timer>0 then
  83.         -- Count Down before arrow appears
  84.         projectiles[id].timer=projectiles[id].timer-1
  85.         if projectiles[id].timer==0 then
  86.             playsound(cc.arrowrain.sfx_attack)
  87.         end
  88.     else
  89.         rot=math.deg(math.atan2(projectiles[id].sx,-projectiles[id].sy))
  90.         -- Wind + Gravity influence on speed
  91.         projectiles[id].sx=projectiles[id].sx+getwind()*0.1
  92.         projectiles[id].sy=projectiles[id].sy+getgravity()*1.5
  93.         -- Move (in substep loop for optimal collision precision)
  94.         msubt=math.ceil(math.max(math.abs(projectiles[id].sx),math.abs(projectiles[id].sy))/3)
  95.         msubx=projectiles[id].sx/msubt
  96.         msuby=projectiles[id].sy/msubt
  97.         for i=1,msubt,1 do
  98.             projectiles[id].x=projectiles[id].x+msubx
  99.             projectiles[id].y=projectiles[id].y+msuby        
  100.             -- Collision
  101.             if collision(col3x3,projectiles[id].x+math.sin(math.rad(rot))*8,projectiles[id].y-math.cos(math.rad(rot))*8)==1 then
  102.                 if playercollision()~=0 then
  103.                     -- Cause Player damage
  104.                     playerpush(playercollision(),projectiles[id].sx/10.0,projectiles[id].sy/10.0)
  105.                     playerdamage(playercollision(),15)
  106.                     blood(projectiles[id].x+math.sin(math.rad(rot))*8,projectiles[id].y-math.cos(math.rad(rot))*8)
  107.                     playsound(sfx_splatter3)
  108.                 elseif objectcollision()~=0 then
  109.                     -- Cause Object damage
  110.                     objectdamage(objectcollision(),15)
  111.                 else
  112.                     -- Draw Arrow in terrain
  113.                     terrainimage(cc.arrowrain.gfx_pro,projectiles[id].x,projectiles[id].y,0,rot)
  114.                 end
  115.                 -- Effects
  116.                 playsound(cc.arrowrain.sfx_impact)
  117.                 particle(p_smoke,projectiles[id].x+math.sin(math.rad(rot))*8,projectiles[id].y-math.cos(math.rad(rot))*8)
  118.                 particlefadealpha(0.006)
  119.                 -- Free projectile
  120.                 freeprojectile(id)
  121.                 return 1
  122.             end
  123.             -- Water
  124.             if (projectiles[id].y)>getwatery()+5 then
  125.                 -- Effects
  126.                 particle(p_waterhit,projectiles[id].x,projectiles[id].y)
  127.                 if math.random(1,2)==1 then
  128.                     playsound(sfx_hitwater2)
  129.                 else
  130.                     playsound(sfx_hitwater3)
  131.                 end
  132.                 -- Free projectile
  133.                 freeprojectile(id)
  134.                 return 1
  135.             end
  136.         end
  137.     end
  138. end